cmake_minimum_required(VERSION 3.5)

project(qt_widget_application_stu VERSION 0.1 LANGUAGES CXX)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Network)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Svg)
set(PROJECT_SOURCES
        main.cpp
        mainwindow.cpp
        mainwindow.h
        mainwindow.ui
)

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)

    # target_sources(qt_widget_application_stu
    #   PRIVATE
    #   01-ui/02-layout/01-h_box_layout/qhboxlayoutstudialog.h 01-ui/02-layout/01-h_box_layout/qhboxlayoutstudialog.cpp 01-ui/02-layout/01-h_box_layout/qhboxlayoutstudialog.ui
    # )

qt_add_executable(qt_widget_application_stu
        MANUAL_FINALIZATION
        ${PROJECT_SOURCES}
        01-list/01-q_list_view/qlistviewdialog.h 01-list/01-q_list_view/qlistviewdialog.cpp 01-list/01-q_list_view/qlistviewdialog.ui
        01-list/02-q_list_widget/qlistwidgetstudialog.h 01-list/02-q_list_widget/qlistwidgetstudialog.cpp 01-list/02-q_list_widget/qlistwidgetstudialog.ui
        02-socket/01-imap/imapstudialog.h 02-socket/01-imap/imapstudialog.cpp 02-socket/01-imap/imapstudialog.ui
        02-socket/02-pop3/pop3studialog.h 02-socket/02-pop3/pop3studialog.cpp 02-socket/02-pop3/pop3studialog.ui
          02-socket/03-smtp/smtpstudialog.h 02-socket/03-smtp/smtpstudialog.cpp 02-socket/03-smtp/smtpstudialog.ui
        b-model/01-mail_model/qmailmodel.h b-model/01-mail_model/qmailmodel.cpp
        01-list/03-q_tree_view/qtreeviewstudialog.h 01-list/03-q_tree_view/qtreeviewstudialog.cpp 01-list/03-q_tree_view/qtreeviewstudialog.ui
        b-model/02-q_project_model/qprojectmodel.h b-model/02-q_project_model/qprojectmodel.cpp
        03-file/02-file_stu_dialog/filestudialog.h 03-file/02-file_stu_dialog/filestudialog.cpp 03-file/02-file_stu_dialog/filestudialog.ui
        03-file/01-file_manager/filemanager.h 03-file/01-file_manager/filemanager.cpp
        b-model/02-q_project_model/projectmodel.h b-model/02-q_project_model/projectmodel.cpp
         05-thread/threadstudialog.h 05-thread/threadstudialog.cpp 05-thread/threadstudialog.ui
         05-thread/loopthread.h 05-thread/loopthread.cpp
         05-thread/noloopthread.h 05-thread/noloopthread.cpp
        02-programmar/01-common/commongrammarstudialog.h 02-programmar/01-common/commongrammarstudialog.cpp 02-programmar/01-common/commongrammarstudialog.ui
        11-util/01-md5_manager/md5manager.h 11-util/01-md5_manager/md5manager.cpp
        b-model/03-smtp_task/smtptask.h b-model/03-smtp_task/smtptask.cpp
        02-socket/03-smtp/smtptaskthread.h 02-socket/03-smtp/smtptaskthread.cpp

        11-util/02-log_manager/logmanager.h 11-util/02-log_manager/logmanager.cpp
        11-util/02-log_manager/logger.h 11-util/02-log_manager/logger.cpp
        11-util/02-log_manager/logevent.h 11-util/02-log_manager/logevent.cpp

        b-model/01-mail_model/folder_model/folderdatasource.h b-model/01-mail_model/folder_model/folderdatasource.cpp
        b-model/01-mail_model/folder_model/foldermodel.h b-model/01-mail_model/folder_model/foldermodel.cpp


        11-util/03-path_manager/pathmanager.h 11-util/03-path_manager/pathmanager.cpp
        svg.qrc
        b-model/04-task/01-imap_task/imaptask.h b-model/04-task/01-imap_task/imaptask.cpp
        b-model/04-task/01-imap_task/imaptaskthread.h b-model/04-task/01-imap_task/imaptaskthread.cpp
        b-model/04-task/01-imap_task/imapparsethread.h b-model/04-task/01-imap_task/imapparsethread.cpp
         b-model/04-task/01-imap_task/imapbasedata.h
         11-util/01-string_codec_manager/stringcodecmanager.h 11-util/01-string_codec_manager/stringcodecmanager.cpp
         04-string/stringstudialog.h 04-string/stringstudialog.cpp 04-string/stringstudialog.ui
         01-ui/03-text_edit/texteditdialog.h 01-ui/03-text_edit/texteditdialog.cpp 01-ui/03-text_edit/texteditdialog.ui

         01-ui/03-text_edit/richeditorwindow.h 01-ui/03-text_edit/richeditorwindow.cpp 01-ui/03-text_edit/richeditorwindow.ui

    )
        # 02-programmar/01-common/commongrammarstudialog.h 02-programmar/01-common/commongrammarstudialog.cpp 02-programmar/01-common/commongrammarstudialog.ui
# Define target properties for Android with Qt 6 as:
#    set_property(TARGET qt_widget_application_stu APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
#                 ${CMAKE_CURRENT_SOURCE_DIR}/android)
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
else()
    if(ANDROID)
        add_library(qt_widget_application_stu SHARED
            ${PROJECT_SOURCES}
        )
# Define properties for Android with Qt 5 after find_package() calls as:
#    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
    else()
        add_executable(qt_widget_application_stu
            ${PROJECT_SOURCES}
        )
    endif()
endif()

# 添加Widget模块
target_link_libraries(qt_widget_application_stu PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
# 添加网络模块
target_link_libraries(qt_widget_application_stu PRIVATE Qt${QT_VERSION_MAJOR}::Network)
# 添加svg模块
target_link_libraries(qt_widget_application_stu PRIVATE Qt${QT_VERSION_MAJOR}::Svg)
# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
# If you are developing for iOS or macOS you should consider setting an
# explicit, fixed bundle identifier manually though.
if(${QT_VERSION} VERSION_LESS 6.1.0)
  set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.qt_widget_application_stu)
endif()
set_target_properties(qt_widget_application_stu PROPERTIES
    ${BUNDLE_ID_OPTION}
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE TRUE
    WIN32_EXECUTABLE TRUE
)

include(GNUInstallDirs)
install(TARGETS qt_widget_application_stu
    BUNDLE DESTINATION .
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

if(QT_VERSION_MAJOR EQUAL 6)
    qt_finalize_executable(qt_widget_application_stu)
endif()
